home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C++ / Snippets / QD3D Juggler / Juggler Sources / CQ3BoxesPane.cp < prev    next >
Encoding:
Text File  |  1995-12-27  |  3.0 KB  |  124 lines  |  [TEXT/CWIE]

  1. //
  2. //    CQ3BoxesPane.cp
  3. //
  4. //    class CQ3BoxesPane
  5. //    A Pane for rendering 4 boxes in a QuickDraw 3D view.
  6. //    Borrowed heavily from the "START HERE" sample code from Apple.
  7. //
  8. //    by James Jennings
  9. //    November 22, 1995
  10. //
  11.  
  12. #include "CQ3BoxesPane.h"
  13. #include "C4BoxMaker.h"    // defines the model
  14. #include "C3Lights.h"    // defines the light group
  15. #include "CCameraMaker.h"    // defines the camera
  16. #include "StQ3Disposer.h"
  17. #include "QD3D Debug Macros.h"
  18. #include <QD3DMath.h>
  19. #include <QD3DTransform.h>
  20.  
  21. CQ3BoxesPane*    
  22. CQ3BoxesPane::CreateQ3BoxesPaneStream(LStream *inStream)
  23. {
  24.     return new CQ3BoxesPane(inStream);
  25. }
  26.  
  27. CQ3BoxesPane::CQ3BoxesPane()
  28. {    // default constructor
  29.     // Does nothing. Must call FinishCreate() later.
  30. }
  31.  
  32. CQ3BoxesPane::CQ3BoxesPane(const CQ3BoxesPane &inOriginal) 
  33.     : CQD3DPane(inOriginal)
  34. {    // copy constructor
  35.     mRotation = inOriginal.mRotation;
  36.     StartIdling();    // start the periodical
  37. }
  38.  
  39. CQ3BoxesPane::CQ3BoxesPane(LStream *inStream)
  40.     : CQD3DPane(inStream)
  41. {    // stream constructor
  42.     // Does nothing. Must call FinishCreate() later.
  43. }
  44.     
  45. CQ3BoxesPane::~CQ3BoxesPane()
  46. {    // destructor
  47. }
  48.  
  49. void
  50. CQ3BoxesPane::FinishCreateSelf()
  51. {    // Inherit the other initialization.
  52.     CQD3DPane::FinishCreateSelf();
  53.  
  54.     // set the rotation matrix to the identity matrix
  55.     ::Q3Matrix4x4_SetIdentity(&mRotation);
  56.     
  57.     StartIdling();    // start the periodical
  58. }
  59.  
  60. void
  61. CQ3BoxesPane::MakeCamera()
  62. {    // Make and add a camera to the current view.
  63.     SDimension16 frameSize;
  64.     GetFrameSize(frameSize);
  65.     CCameraMaker theCamera(frameSize);    // construct a camera
  66.     TQ3Status status = ::Q3View_SetCamera(mView, theCamera.Get());
  67.     ThrowIfQ3Fail_(status);
  68. }
  69.  
  70. void
  71. CQ3BoxesPane::MakeLightGroup()
  72. {
  73.     C3Lights theLights;
  74.     // add the lights to the group
  75.     TQ3Status status = ::Q3View_SetLightGroup(mView, theLights.Get());
  76.     ThrowIfQ3Fail_(status);
  77. }
  78.  
  79. void
  80. CQ3BoxesPane::MakeModel()
  81. {
  82.     // construct the model
  83.     C4BoxMaker theBoxes;
  84.     // get the model and store a reference to it.
  85.     mModel = ::Q3Shared_GetReference(theBoxes.Get());
  86.     ThrowIfNil_(mModel);
  87. }
  88.  
  89. TQ3Status
  90. CQ3BoxesPane::SubmitScene()
  91. {    // Submit the stuff we have in our scene.
  92.     // Don't throw anything from inside this function, else
  93.     // ::Q3View_EndRendering() never gets called.
  94.     TQ3Status status;
  95. /*    status = ::Q3Style_Submit( mInterpolation, mView );
  96.     if (status==kQ3Failure) return status;
  97.     status = ::Q3Style_Submit( mBackFacing, mView );
  98.     if (status==kQ3Failure) return status;
  99.     status = ::Q3Style_Submit( mFillStyle, mView );
  100.     if (status==kQ3Failure) return status;*/
  101.     
  102.     // Do the inherited stuff (interpolation, backfacing, fillstyle)
  103.     status = CQD3DPane::SubmitScene();
  104.     if (status==kQ3Failure) return status;
  105.     // Do the rotation.
  106.     status = ::Q3MatrixTransform_Submit( &mRotation, mView );
  107.     if (status==kQ3Failure) return status;
  108.     // Do the model.
  109.     status = ::Q3DisplayGroup_Submit( mModel, mView );
  110.     return status;
  111. }
  112.  
  113. void
  114. CQ3BoxesPane::SpendTime( const EventRecord &inMacEvent)
  115. {    // on each null event, spin a little.
  116.     TQ3Matrix4x4    tmp;
  117.     
  118.     ::Q3Matrix4x4_SetRotate_XYZ(&tmp, 0.1, 0.12, 0.08);
  119.     ::Q3Matrix4x4_Multiply(&mRotation, &tmp, &mRotation);
  120.  
  121.     Refresh();
  122. }
  123.  
  124.